import React from 'react';
export default class KeyDemo extends React.Component{
  constructor(){
    super();
    this.state = {
      list: ['1', '2', '3']
    }
  }
  addHandle = () => {
    let listShadow = this.state.list;
    listShadow.push(this.state.list.length + 1);
    this.setState({
      list: listShadow
    })
  }
  render(){
    const { list } = this.state;
    return(
      <div>
        <ul>
          { list.map((item, index)=>{
            return(
              <li key={index}>{item}</li>
            )
          }) }
        </ul>
        <button onClick={ this.addHandle }>添加</button>
      </div>
    )
  }
}